<template>
  <div>
    <div v-if="index === 0">
      <div
        class="newsong"
        v-for="(item, index) in list1"
        :key="index"
        @click="newsong(item.id)"
      >
        <div class="newsong-img">
          <img :src="item.picUrl" alt="" />
        </div>
        <span class="newspan">{{ item.name }}</span>
        <br />
        <span class="geshou"> {{ item.song.artists[0].name }} </span>
      </div>
    </div>
    <div v-else>
      <div
        class="newsong"
        v-for="(item, index) in list2"
        :key="index"
        @click="newsong(item.id)"
      >
        <div class="newsong-img">
          <img :src="item.picUrl" alt="" />
        </div>
        <span class="newspan">{{ item.name }}</span>
        <br />
        <span class="geshou"> {{ item.song.artists[0].name }} </span>
      </div>
    </div>
  </div>
</template>

<script>
import { GetnewSong } from '@/api/home'
export default {
  props: {
    index: {
      type: Number,
      required: true
    }
  },
  data () {
    return {
      list: [],
      list1: [],
      list2: [],
      limit: 6
    }
  },
  created () {
    this.GetnewSong()
  },
  mounted () {},
  methods: {
    async GetnewSong () {
      const { result } = await GetnewSong(this.limit)
      this.list = result
      this.list.forEach((item, index) => {
        if (index > 2) {
          this.list1.push(item)
        } else {
          this.list2.push(item)
        }
      })
      console.log(this.list1)
      console.log(this.list2)
    },
    newsong (id) {
      this.$router.push(`/play${id}`)
    }
  }
}
</script>

<style scoped lang="less">
.newsong {
  overflow: hidden;
  .newsong-img {
    width: 100px;
    height: 100px;
    float: left;
    img {
      width: 100%;
      height: 100%;
      vertical-align: text-top;
    }
  }
  .geshou {
    font-size: 12px;
    color: #999;
  }
  span {
    float: left;
    width: 300px;
    font-size: 30px;
    overflow: hidden;
    -webkit-line-clamp: 1;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
  }
}
</style>
